package com.base.llpark.presenter;

import android.app.Activity;
import android.view.View;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.RealNetWorkUtil;
import com.base.commonlib.http.utils.CallBackImpl;
import com.base.llpark.bean.LlParkBean;
import com.base.llpark.view.ParkHistoryListView;

import java.util.HashMap;

import io.reactivex.disposables.Disposable;

/**
 * Created by weikailiang on 2019/10/26.
 */

public class ParkHistoryListPresenter extends BasePresenter<ParkHistoryListView>{

    public ParkHistoryListPresenter(ParkHistoryListView view, Activity activity) {
        super(view, activity);
    }

    public void getHistoryList(final String index) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("page",Integer.valueOf(index));
        map.put("limit", 10);
        Disposable enqueue = RealNetWorkUtil.postContent().method("api-ll/illegal/selectUnReport").content(map)
                .build().enqueue(LlParkBean.class, new CallBackImpl<LlParkBean>() {
                    @Override
                    public void onError(int code, String msg, String errMsg) {
                        mView.showError();
                        mView.returnError();
                    }

                    @Override
                    public void onNext(LlParkBean list) {
                        if (index.equals("1")){
                            //刷新
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnList(list.getRows());
                            }else {
                                mView.returnNoData();
                            }
                        }else {
                            //更多
                            if (list!=null &&list.getRows() != null&&list.getRows().size()>0){
                                mView.returnMoreList(list.getRows());
                            }else {
                                mView.returnNoMoreData();
                            }
                        }
                    }
                });

        mCompositeDisposable.add(enqueue);
    }
}
